//@note 类别选择组件
//@author czh
put('category',function(){
	
	var headStr = '<div class="w-loc-head"><a id="wCatFinal" class="w-loc-arrow iconfont" href="javascript:void(0);">&#xf0292;</a><span class="w-loc-txt">选择分类</span></div>' ;
	
	var provinceStr = '<div id="widgetCatList" class="w-loc-list"></div>' ;
	var bodyStr = '<div class="w-loc-body"><div class="w-loc-title">点击选择分类</div>' + provinceStr + '</div>' ;
	var htmlStr = '<div id="widgetCat" class="w-loc">'  + 
					headStr  + bodyStr + '</div>' ;
	
	$('body').append(htmlStr) ;
	
	var emitCatEvent = function(){
		$('.m-cat-item').on('click',function(){				
			var selectClass = 'w-loc-citySel' ;
			if($(this).hasClass(selectClass)){
				$(this).removeClass(selectClass) ;
			}else{
				$(this).addClass(selectClass) ;
			}
		});		
	} ;
	$.ajax({
		url : window.appRoot + '/infoCategory.html' ,
		method : 'get' ,
		success : function(list){
			var panel = $('#widgetCatList') ;
			panel.html('') ;
			var createItem = function(json){
				return '<a href="javascript:void(0);" class="m-cat-item w-loc-item"><span data-id="'+json.id+'" class="w-loc-txtWrap">'+json.name+'</span><span class="w-locl-gou" >&radic;</span></a>';
				} ;
			for(var i = 0 ; i < list.length ; i++ ){
				panel.append(createItem(list[i])) ;
			}
			emitCatEvent() ;
		}
	}) ;
	
	var bodyCss = {
		_ele : $('body') ,
		set : function(){
			this._ele.css('overflow','hidden');
			var self = this ;
			$('.w-loc').css({
				'height' : $(window).height() 
			});
		} ,
		reset : function(){
			this._ele.css('overflow','auto');
		}
	} ;
	
	
	$('#wCatSelect').on('click','.w-cat-selPoint',function(){
		$(this).remove();
	})
	
	var finalCall = function(){} ;
	
	$('#wCatFinal').on('click',function(){
		var list = [] ;
		$('#widgetCatList .w-loc-citySel').each(function(){
			var me = $(this).find('span.w-loc-txtWrap') ;
			list.push({id:me.attr('data-id'),name:me.html()}) ;
		}) ;
		finalCall(list);
		$('#widgetCat').css('left','21rem'); 
		bodyCss.reset();
	}) ;
	return {
		open : function(callback){
			var wrap = $('#widgetCat') ;
			try{
				wrap[0].clientLeft ;
			}catch(ev){}
			if( typeof callback === 'function' ){
				finalCall = callback ;
			}
			wrap.css({'left':'0'}) ;
			bodyCss.set() ;
		},
		close : function(){
			var wrap = $('#widgetLoc') ;
			wrap.css('left','21rem') ;
			bodyCss.reset() ;
		}
	} ;
	
}) ;